<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	
	/*public function __construct()
	{
		parent::__construct();
		$this->load->model('news_model');
	}*/
	/*
	public function _remap($method, $params = array())
	{
		$this->index();
		
	}*/
	
	public function index($page = 'home') //to be used for homepage, about_us page only
	//also being used to load homework page for the time being but that needs to be changed
	{
		if ( ! file_exists('application/views/'.$page.'.php'))
		{
			// Whoops, we don't have a page for that!
			show_404();
		}

		$data['title'] = ucfirst($page); // Capitalize the first letter
		$this->load->helper('url');
		
		$this->load->view('templates/header', $data);
		$this->load->view($page, $data);
		$this->load->view('templates/footer', $data);
	}
	
	public function news_index()
	{
		$this->load->helper('url');
		$this->load->model('news_model');
		$data['news'] = $this->news_model->get_news();
		
		$data['title'] = 'News archive';
		$data['mode'] = 'client';	
		$data['type'] = 'news';
		$this->load->view('templates/header', $data);
		$this->load->view('news_index', $data);
		$this->load->view('templates/footer');
	}
	
	public function news_view($slug)
	{
		$this->load->helper('url');
		$this->load->model('news_model');
		$data['mode'] = 'client';
		$data['type'] = 'news';
		$data['news_item'] = $this->news_model->get_news('news', $slug);
		
		if (empty($data['news_item']))
		{
			show_404();
		}
		
		$data['title'] = $data['news_item']['title'];
		
		$this->load->view('templates/header', $data);
		$this->load->view('news', $data);
		$this->load->view('templates/footer');
	}
	
	public function report()
	{
		$this->load->helper('url');
		$this->load->model('news_model');
		$this->load->helper('form');
		$this->load->library('form_validation');
	
		$data['title'] = 'Report a news';
	
		$this->form_validation->set_rules('title', 'Title', 'required');
		$this->form_validation->set_rules('text', 'text', 'required');
	
		if ($this->form_validation->run() === FALSE)
		{
			$this->load->view('templates/header', $data);
			$this->load->view('report');
			$this->load->view('templates/footer');
	
		}
		else
		{
			$this->news_model->set_report();
			$this->load->view('templates/header', $data);
			$this->load->view('success');
			$this->load->view('templates/footer');
		}
	}
	
	
	public function gossip_index()
	{
		$this->load->helper('url');
		$this->load->model('news_model');
		
		$data['gossip'] = $this->news_model->get_news('gossip');
		$data['title'] = 'News archive';
		$data['mode'] = 'client';
		$data['type'] = 'gossip';
		
		$this->load->view('templates/header', $data);
		$this->load->view('gossip_index', $data);
		$this->load->view('templates/footer');
	}
	
	public function gossip_view($slug)
	{
		$this->load->helper('url');
		$this->load->model('news_model');
		
		$data['mode'] = 'client';
		$data['type'] = 'news';
		$data['news_item'] = $this->news_model->get_news('gossip', $slug);
		
		if (empty($data['news_item']))
		{
			show_404();
		}
		
		$data['title'] = $data['news_item']['title'];
		
		$this->load->view('templates/header', $data);
		$this->load->view('news', $data);
		$this->load->view('templates/footer');
	}

}


/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */